package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.service.db.BlackListService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findBlackListByUid(Long userId, Integer pageNum, Integer pageSize) {
        System.out.println(pageNum+"@@@@"+pageSize);
        //开启分页
        IPage<UserInfo> iPage = new Page<>(pageNum,pageSize);
        //调用分页查询
        iPage = blackListMapper.findBlackListByUid(iPage, userId);
        //返回pageBeanVo对象
        return new PageBeanVo(pageNum, pageSize, iPage.getTotal(), iPage.getRecords());
    }

    @Override
    public void deleteByUid(Long userId,Long blackUserId) {
        QueryWrapper<BlackList> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("black_user_id", blackUserId);
        blackListMapper.delete(wrapper);
    }
}
